import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBBaseUtils/YBCallPhoneUtils.dart';



class YBNewFindWebView extends StatefulWidget {

  final String webStr;

  const YBNewFindWebView({Key key, this.webStr}) : super(key: key);

  @override
  _YBNewFindWebViewState createState() => _YBNewFindWebViewState(webStr: webStr);
}

class _YBNewFindWebViewState extends State<YBNewFindWebView> {

  final String webStr;

  _YBNewFindWebViewState({this.webStr});

  WebViewController _controller;

  String _titleStr = "";

  @override
  void dispose() {
    // TODO: implement dispose
    EasyLoading.dismiss();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    return Container(
      color: YBColor.white,
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Container(
            child: Text(_titleStr,style:YBTextStyle.TextStyle30313320Medium,),
          ),
        ),
        body:WebView(
          initialUrl: webStr,
          javascriptMode: JavascriptMode.unrestricted,
          onPageStarted: (String url){
            EasyLoading.show(status: "读取中...");
          },
          onWebViewCreated: (controller){
            _controller = controller;
          },
          javascriptChannels: <JavascriptChannel>[
            JavascriptChannel(name: "commtjToast", onMessageReceived:(JavascriptMessage message){
              print("object--${message.message}---");
              YBCallPhoneUtils().getCallPhoneUtils("tel:${message.message}");
            }),
          ].toSet(),
          onPageFinished:(String url){
            EasyLoading.dismiss();
            _controller.evaluateJavascript("document.title").then((value){
              setState(() {
                _titleStr = value;
                print("-----------$value--------");
              });
            });
          },
        ),
      ),
    );
  }
}

